package Thread;

import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

//仅基于String为参数
class MyBlockinbgQueue {
    String[] data = null;

    private int head = 0;

    private int tail = 0;

    private int size = 0;

    //循环队列
    public MyBlockinbgQueue(int capicity) {
        data = new String[capicity];
    }

    public void put(String s) throws InterruptedException {
        synchronized (this) {
            while (size == data.length) {
                //队列满了
                //return;
                this.wait();
            }
            data[tail] = s;
            tail++;
            if (tail >= data.length) {
                tail = 0;
            }
            size++;
            this.notify();
        }
    }
    public String take() throws InterruptedException {
        String ret = "";
        synchronized (this) {
            while (size == 0) {
                //队列空了
                //return null;
                this.wait();
            }
            ret = data[head];
            head++;
            if (head >= data.length) {
                head = 0;
            }
            size--;
            this.notify();
        }
        return ret;
    }
}

public class demo15 {
    public static void main(String[] args) throws InterruptedException {

    }
}
